<%@page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>项目信息审核</title>
<%@ include file="../../common/common.jsp"%>
	
<script type="text/javascript">

var contractinfo_id =  parent.document.getElementById("countractId").value;

function statusFormatter(value,row,index){
	if (value==1){
		var s = '<a href="#" onclick="saverow('+index+')">已编制</a> ';
		return s;
	} else {
		var e = '<a href="#" onclick="editrow('+index+')">未编制</a> ';
		return e;
	}
}

function pro_statusFormatter(value,row,index){
	if (value==0){
		var s = '未编制';
		return s;
	}
	if (value==1){
		var s = '已编制';
		return s;
	}
	if (value==2){
		var s = '已审核';
		return s;
	}
}


$(function(){
		$('#dg').datagrid({
			url:"<%=basePath %>loadProjectInfoAction.do?projectInfo.contractinfo_id="+contractinfo_id,
			view: detailview,
			detailFormatter:function(index,row){
				return '<div style="padding:2px"><table id="ddv-' + index + '"></table></div>';
			},
			onExpandRow: function(index,row){
				
				$('#ddv-'+index).datagrid({
					url:'<%=basePath%>loadProWorkDetailAction.do?projectWorkInfo.projectinfo_id='+row.id,
					fitColumns:true,
					singleSelect:true,
					width:'600',
					height:'auto',
					rowStyler:function(index,row){
						if (row.workInfoStatus==0){
							return 'background-color:pink;color:blue;font-weight:bold;';
						}
					},
					columns:[[
						{field:'cesspoolNo',title:'化粪池编号',width:30},
						{field:'cesspoolType',title:'类型',width:20},
						{field:'cesspoolDoPerson',title:'施工分队',width:30},
						{field:'cesspoolBudgetPrice',title:'预算价',width:30},
						{field:'cesspoolDoContent',title:'工程内容',width:50},
						{field:'workInfoStatus',title:'状态',width:30,formatter:statusFormatter}
					]],
					onResize:function(){
						$('#dg').datagrid('fixDetailRowHeight',index);
					},
					onLoadSuccess:function(){
						setTimeout(function(){
							$('#dg').datagrid('fixDetailRowHeight',index);
						},0);
					},
					onClickRow:function(rowIndex,rowData){
						//alert('id:'+rowData.id);
						$('#projectWorkInfoId').attr('value',rowData.id);
						_open_bz_page ();
						
					}
				});
				$('#dg').datagrid('fixDetailRowHeight',index);
			}
		});
});


				
function _open_bz_page () {
	var url = "open_budget_do.jsp";
$('<div><iframe frameborder="0" scrolling="no" marginheight="0" framespacing=0 marginwidth="0" '+
		'"FrameBorder=0 src="'+url+'" style="width:100%;height:100%; "/></div>').dialog({			
			open : function() {
			},
			height : 310,
			width : 550,
			title : '审核预算'
		});
}

//审核改变合同状态
function _fun_audit (){
	
	
	var rows = $('#dg').datagrid('getRows');
	var  f = true;
	for(var i=0;i<rows.length;i++){
		var p = rows[i].projectStatus;
		if(p<2){
			$.messager.alert('提示','项目『'+rows[i].projectName+'』未进行项目审核， 无法确认完成');
			f = false;
			break;
		}
	}
	
	if(!f){
		return;
	}	
	var params = {
			id:contractinfo_id,
			contractStatus:2
			};
	var url = baseURL+"/saveContractAction!audit.do";
	
	$.messager.confirm('提示','请确认是否完成了所有项目的审核',function(r){  
	      if (r){  
	    		jQuery.post(url,params,function(data){
	    			//alert(data.message);
	    			if(data.message!='' && "success"==data.message){
	    				window.close(); // close the dialog
	    				parent.window.location.reload(); // reload the user data
	    				 
	    			}
	    		
	    	},'json');
	      }  
	 }); 
}	
//审核项目	
function _pro_audit (projectInfo_id,projectStatus){
		
		var params = {
				id:projectInfo_id,
				projectStatus:projectStatus
				};
		var url = baseURL+"/saveProjectInfoAction!audit.do";
		$.messager.confirm('提示','请确认是否完成项目审核',function(r){  
		      if (r){  
		    		jQuery.post(url,params,function(data){
		    			//alert(data.message);
		    			if(data.message!='' && "true"==data.message){
		    				window.location.reload(); // reload the user data
		    			}
		    		
		    	},'json');
		      }  
		 }); 
		
}

function formatAction(value,row,index){
	if (row.projectStatus==1){
		var s = '<a href="#" onclick="_pro_audit('+row.id+',2)">审核项目</a> ';
		return s;
	}
	if (row.projectStatus==2){
		var s = '<a href="#" onclick="_pro_audit('+row.id+',2)">审核项目</a> ';
		return s;
	} 
}
		

</script>
</head>
<body>
		
<table id="dg" style="width:980px;height:320px"
			title="项目信息"
			singleSelect="true" fitColumns="true" >
		<thead>
			<tr>
				<th field="projectName" align="center" width="40">项目名称</th>
				<th field="constructionOrganization" align="center" width="20">施工单位</th>
				<th field="pipeLength" width="20" >管道长度</th>
				<th field="managerCompanyInfo" width="20" align="center">物管信息</th>
				<th field="residentCount" width="15" align="center">总户数</th>
				<th field="buildArea" width="15" align="center">总面积</th>
				<th field="pitCount" width="20" align="center">化粪池数</th>
				<th field="budgetPrice" width="20" align="center">项目预算</th>
				<th field="projectStatus" width="15" align="center" formatter="pro_statusFormatter">状态</th>
				<th field="createTime" width="30" align="center">创建时间</th>
				<th field="projectSpec" width="40" align="center">项目说明</th>
				<th field="action" width="20" align="center" formatter="formatAction">操作</th>
			</tr>
		</thead>
</table>
	
<div id="dlg-buttons" align="center">
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
				onclick="_fun_audit()">确认审核</a>
</div>
		
</body>
</html>